﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Managers.*;
    import Engine.Helpers.*;
    import Events.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.MarketUI.*;
    import Modules.stats.types.*;

    public class TExpandFarm extends TFarmTransaction {

        protected var m_itemName:String;
        protected var m_location:Vector2;
        protected var m_trees:Array;
        protected var m_originalTrees:Array;

        public function TExpandFarm(_arg1:String, _arg2:Vector2, _arg3:Array){
            var _local5:Object;
            super();
            this.m_itemName = _arg1;
            this.m_location = _arg2;
            this.m_originalTrees = _arg3;
            this.m_trees = new Array();
            var _local4:int;
            for each (_local5 in _arg3) {
                this.m_trees[_local4] = {
                    x:_local5.x,
                    y:_local5.y,
                    dir:_local5.dir,
                    itemName:_local5.itemName,
                    id:_local5.id
                };
                _local4++;
            };
            UI.displayMessage(ZLoc.t("Main", "ExpandFarmComplete"), GenericPopup.TYPE_OK, null, "", true);
            Sounds.play("land_expand");
            Global.player.m_licenses[this.m_itemName] = 0;
            MarketCell.reLockCells(this.m_itemName);
        }
        override public function perform():void{
            signedCall("FarmService.expandCity", this.m_itemName, this.m_location, this.m_trees);
        }
        protected function onExpandFarmFeed(_arg1:GenericPopupEvent):void{
        }
        override protected function onComplete(_arg1:Object):void{
            var _local2:Array;
            var _local3:int;
            var _local4:int;
            var _local5:GameObject;
            var _local6:int;
            if (_arg1 != null){
                _local2 = (_arg1 as Array);
                _local3 = 0;
                if (_local2){
                    if (this.m_originalTrees.length == _local2.length){
                        _local4 = 0;
                        while (_local4 < this.m_originalTrees.length) {
                            _local5 = GameObject(this.m_originalTrees[_local4].wildernessObj);
                            if (_local5.getId() == _local2[_local4].id){
                                _local6 = _local2[_local4].newId;
                                if (_local6 != 0){
                                    _local5.setId(_local6);
                                    _local3++;
                                };
                            };
                            _local4++;
                        };
                    };
                };
                if (_local3 != this.m_originalTrees.length){
                    ErrorManager.addError("Warning: TExpandFarm failed to remap ids.");
                };
                StatsManager.count(StatsCounterType.EXPANSION, this.m_itemName, TrackedActionType.PLACE, (((("(" + this.m_location.x) + ",") + this.m_location.y) + ")"));
            };
        }

    }
}//package Transactions 
